/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.gateway.core.exception;

import info.peigen.hotpot.common.core.enums.Messageable;

import java.io.Serial;

/**
 * <b>(GatewayBusinessException)</b>
 * 标记事务可回滚的业务异常,配合声明式事务使用 <br/>
 * 业务系统可以根据业务需求，继承该类定义具体业务相关的业务。如：NoFoundException, ParameterInvaidException 等。
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2021/4/8
 */
public class GatewayBusinessException extends RuntimeException implements Messageable {

    @Serial
    private static final long serialVersionUID = 1L;

    private String code = "SYSTEM";

    public GatewayBusinessException() {
        super();
    }

    public GatewayBusinessException(String message) {
        super(message);
    }

    /**
     * @param message            错误消息
     * @param writableStackTrace 是否收集线程栈信息，对于业务明确的异常，请关闭,设置为false为关闭
     */
    public GatewayBusinessException(String message, boolean writableStackTrace) {
        super(message, null, false, writableStackTrace);
    }

    /**
     * @param message            错误消息
     * @param writableStackTrace 是否收集线程栈信息，对于业务明确的异常，请关闭,设置为false为关闭
     */
    public GatewayBusinessException(String message, String code, boolean writableStackTrace) {
        super(message, null, false, writableStackTrace);
        this.code = code;
    }

    public GatewayBusinessException(String message, Throwable cause) {
        super(message, cause);
    }

    public GatewayBusinessException(Throwable cause) {
        super(cause);
    }

    public GatewayBusinessException(String message, String code) {
        super(message);
        this.code = code;
    }

    public GatewayBusinessException(String message, Throwable cause, String code) {
        super(message, cause);
        this.code = code;
    }

    public GatewayBusinessException(Throwable cause, String code) {
        super(cause);
        this.code = code;
    }

    public GatewayBusinessException(Messageable messageable) {
        super(messageable.message());
        this.code = messageable.code();
    }

    public GatewayBusinessException(Messageable messageable, String msg) {
        super(msg);
        this.code = messageable.code();
    }

    public GatewayBusinessException(Messageable messageable, Throwable cause) {
        super(messageable.message(), cause);
        this.code = messageable.code();
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Override
    public String code() {
        return this.code;
    }

    @Override
    public String message() {
        return this.getMessage();
    }
}